using UnityEngine;

public class PlayerAI
{
	public Player player;

	public StateMachine<PlayerAI> stateMachine;

	public float time_Stop;

	public bool offense_dribble_is_shoot_without_defense;

	public bool offense_dribble_is_shoot_on_defense;

	public bool offense_dribble_is_ok_layup_or_dunk;

	public float offense_dribble_time_ok_layup_or_dunk_keepmove;

	public int offense_crossover_count;

	public float offense_crossover_time_wait;

	public float offense_crossover_time_crossing;

	public bool offense_crossover_is_crossing;

	public bool offense_shoot_is_rebound;

	public Vector3 offense_findpos_targetpos;

	public int offense_findpos_index;

	public Vector3 offense_getloose_direction;

	public Vector3 freethrow_pos;

	public Vector3 freethrow_direction;

	public bool freethrow_isHandAnimation;

	public Vector3 defense_defense_pos_target;

	public bool defense_rebound_is_toBall;

	public float defense_defense_time_steal;

	public float defense_defense_time_chase;

	public PlayerAI(Player _player)
	{
		player = _player;
		stateMachine = new StateMachine<PlayerAI>(this);
	}

	public void fixedUpdate()
	{
		stateMachine.fixedUpdate();
	}

	public void OnJumpBall()
	{
		setCrossoverCount();
		defense_defense_time_chase = 0f;
		time_Stop = 0f;
		player.LookAt(MathHelper.setY(Instance<Ball>.instance.getPosition(), 0f));
	}

	public void setCrossoverCount()
	{
		if (player.heightType == HeightType.BIG)
		{
			offense_crossover_count = player.team.count_crossover_big;
		}
		else if (player.heightType == HeightType.NORMAL)
		{
			offense_crossover_count = player.team.count_crossover_normal;
		}
		else
		{
			offense_crossover_count = player.team.count_crossover_small;
		}
	}

	public void turnDirection()
	{
		if (Random.Range(0, 2) == 0)
		{
			player.myTransform.Rotate(new Vector3(0f, Random.Range(30f, 89f), 0f));
		}
		else
		{
			player.myTransform.Rotate(new Vector3(0f, Random.Range(-30f, -89f), 0f));
		}
	}

	public void do_idle()
	{
		changeState(PlayerAIState_Idle.getInstance());
	}

	public void do_jumpball()
	{
		changeState(PlayerAIState_JumpBall.getInstance());
	}

	public void do_baseline(Vector3 targetPos)
	{
		player.bassline_targetPos = targetPos;
		changeState(PlayerAIState_BaseLine.getInstance());
	}

	public void do_acceptbaselineball()
	{
		changeState(PlayerAIState_AcceptBaseLineBall.getInstance());
	}

	public void do_baseline_after()
	{
		changeState(PlayerAIState_AfterBaseLine.getInstance());
	}

	public void do_tumble()
	{
		changeState(PlayerAIState_Tumble.getInstance());
	}

	public void do_chase_ball()
	{
		changeState(PlayerAIState_ChaseBall.getInstance());
	}

	public void do_offense_dribble()
	{
		changeState(PlayerAIState_Offense_Dribble.getInstance());
	}

	public void do_offense_shoot()
	{
		changeState(PlayerAIState_Offense_Shoot.getInstance());
	}

	public void do_offense_freethrow()
	{
		changeState(PlayerAIState_Offense_FreeThrow.getInstance());
	}

	public void do_offense_crossover()
	{
		changeState(PlayerAIState_Offense_CrossOver.getInstance());
	}

	public void do_offense_grabrebound()
	{
		changeState(PlayerAIState_Offense_GrabRebound.getInstance());
	}

	public void do_offense_findpos()
	{
		changeState(PlayerAIState_Offense_FindPos.getInstance());
	}

	public void do_offense_getloose()
	{
		changeState(PlayerAIState_Offense_GetLoose.getInstance());
	}

	public void do_offense_pass()
	{
		changeState(PlayerAIState_Offense_Pass.getInstance());
	}

	public void do_offense_catch()
	{
		changeState(PlayerAIState_Offense_CatchBall.getInstance());
	}

	public void do_defense_defense()
	{
		changeState(PlayerAIState_Defense_Defense.getInstance());
	}

	public void do_defense_freethrow()
	{
		changeState(PlayerAIState_Defense_FreeThrow.getInstance());
	}

	public void do_defense_helpdefense()
	{
		changeState(PlayerAIState_Defense_HelpDefense.getInstance());
	}

	public void do_defense_steal()
	{
		changeState(PlayerAIState_Defense_Steal.getInstance());
	}

	public void do_defense_steal_grab()
	{
		changeState(PlayerAIState_Defense_Steal_Grab.getInstance());
	}

	public void do_defense_block()
	{
		changeState(PlayerAIState_Defense_Block.getInstance());
	}

	public void do_defense_grabrebound()
	{
		changeState(PlayerAIState_Defense_GrabRebound.getInstance());
	}

	public void do_quarterend()
	{
		changeState(PlayerAIState_QuarterEnd.getInstance());
	}

	public bool isInState(State<PlayerAI> state)
	{
		return stateMachine.isInState(state);
	}

	public void changeState(State<PlayerAI> state)
	{
		if (!isInState(state))
		{
			stateMachine.changeState(state);
		}
	}

	public Vector3 getAvailableOffensePos()
	{
		offense_findpos_index = player.team.getOffensePosAvailableIndex();
		return (player.getOffenseDirection() != 0) ? Global.posOffense_Right[offense_findpos_index] : Global.posOffense_Left[offense_findpos_index];
	}
}
